package com.xsz.lambdademo;

import java.util.function.Function;

//java.util.function.Function<T, R>接口定义了一个叫作apply的方法，
// 它接受一个泛型T的对象，
// 并返回一个泛型R的对象，函数描述符为(T) -> R。举个例子：
//        1234 Function<Apple, Double> getAppleWeight = (a) -> {
//        return a.getWeight();};getAppleWeight.apply(new Apple(17)); // 17.0
public class FunctionsDemo {
    public static void main(String[] args) {
        Function<Apple, Double> getAppleWeight = (a) -> {
            return a.getWeight();
        };
        getAppleWeight.apply(new Apple("red",17)); // 17.0


        Function<Integer, Integer> f = (x) -> x + 1;
        Function<Integer, Integer> g = (x) -> x * 2;
        f.andThen(g).apply(2); // 6


        Function<Person, String> getPersonName = (a) -> {
            return a.getName();
        };

        Person p3=new Person();
        p3.setName("张三");

        String n1=getPersonName.apply(p3);
        System.out.println(n1);

    }
}
